package Thread.Thread_Attributes;


public class Demo15 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(()->{
            for (int i = 0; i < 3; i++) {
                System.out.println("这是线程t1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程t1 结束");
        });
        Thread t2=new Thread(()->{
            for (int i = 0; i < 4; i++) {
                System.out.println("这是线程t2");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程t2 结束");
        });
        t1.start();
        t2.start();
        System.out.println("main 线程开始等待");
        //并不只是main去等待其他线程，任意线程之间都是可以相互等待的
        t1.join();
        t2.join();
        System.out.println("main 线程等待结束");
    }
}
